package band.wukong.practice.webservice.kh.sample09.nongen;

import band.wukong.practice.webservice.kh.sample09.BinaryService;
import band.wukong.practice.webservice.kh.sample09.BinaryServiceImplService;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import javax.xml.ws.soap.MTOMFeature;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;

/**
 * @author wukong(wukonggg@139.com)
 */
public class ClientTest {

    private static final Logger logger = LoggerFactory.getLogger(ClientTest.class);

    private BinaryService port;

    @BeforeClass
    public void init() throws MalformedURLException {
//  TODO 这里不知道为啥MTOM方式不能用代理。不用代理正常，一用代理就报错。
//        URL proxyUrl = new URL("http://localhost:9001/wkp/webservice/kh/sample09?wsdl");
//        QName proxyQName = new QName(NS, "BinaryServiceImplService");
//        BinaryServiceImplService service = new BinaryServiceImplService(proxyUrl, proxyQName);
        BinaryServiceImplService service = new BinaryServiceImplService();

        port = service.getBinaryServiceImplPort(new MTOMFeature()); // MTOM模式
//        port = service.getBinaryServiceImplPort();    // 非MTOM模式
    }

    @Test
    public void upload() {
        try {
            byte[] file = FileUtils.readFileToByteArray(new File("D:/1.png"));
            port.upload(file);
            byte[] result = FileUtils.readFileToByteArray(new File("D:/2.png"));
            Assert.assertNotNull(result);
        } catch (IOException e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }

    }

}
